var ming='Xiao ming';
語法基本單元化-在這個步驟,只有單純地將程式碼逐步解析,=
不會被視作指派,而是符號
[
{
//var 被解析為關鍵字
"type": "Keyword",
"value": "var"
},
{
//ming 被解析為識別符
"type": "Identifier",
"value": "ming"
},
{
//=被解析為符號
"type": "Punctuator",
"value": "="
},
{
//'Xiao ming'被解析為字串
"type": "String",
"value": "'Xiao ming'"
},
{
"type": "Punctuator",
"value": ";"
}
]
抽象結構樹化,注意,此時亦未執行代碼功能(賦值)
{
"type": "Program",
"body": [
//陣列每一元素皆為一組語意
{
//解析出語意為變數宣告
"type": "VariableDeclaration",
"declarations": [
{
//變數宣告者
"type": "VariableDeclarator",
"id": {
//變數辨識符
"type": "Identifier",
"name": "ming"
},
"init": {
//變數值
"type": "Literal",
"value": "Xiao ming",
"raw": "'Xiao ming'"
}
}
],
//變數定義方式
"kind": "var"
}
],
"sourceType": "script"
}
取
右側變數的值
賦
值左側變數
//LHS
var ming='Xiao ming';
//編譯時期報錯
'Xiao ming'='man'
//RHS
console.log(ming);
var man=ming;
//編譯時期不會報錯
console.log(a)